import axios from 'axios'

export function getLocalCity() {
  const localCity = JSON.parse(localStorage.getItem('hkzf_city'))

  if(!localCity) {
    return new Promise((reslove, reject) => {
      const myCity = new window.BMap.LocalCity()
      myCity.get(async result => {
        const cityName = result.name
        const {data} = await axios.get(`http://127.0.0.1:8080/area/info?name=${cityName}`)
        reslove(data.body)    
        localStorage.setItem('hkzf_city', JSON.stringify(data.body))
      })
    })
  }

  return Promise.resolve(localCity)

}
